package com.wt.struggle.goodbye.user.activity

import android.os.Bundle
import android.support.v4.view.PagerAdapter
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.wt.struggle.goodbye.R
import com.wt.struggle.goodbye.base.Config
import com.wt.struggle.goodbye.base.ProActivity
import com.wt.struggle.goodbye.info.NetInfo
import com.wt.struggle.goodbye.info.NewsInfo
import com.xin.lv.yang.utils.utils.ImageUtil
import com.xin.lv.yang.utils.view.ZoomImageView
import kotlinx.android.synthetic.main.head.*
import kotlinx.android.synthetic.main.show_image_layout.*

/**
 * 显示图片
 */
class ShowImageActivity : ProActivity() {

    override fun handler(what: Int, arg1: Int, netInfo: NetInfo) {

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.show_image_layout)
        tvTitle.text = "图片详情"

        imageBack.setOnClickListener {
            finish()
        }

        val arr: ArrayList<String> = intent.getStringArrayListExtra("arr")
        showData(arr)
    }

    val viewPagerList = arrayListOf<View>()

    private fun showData(arr: ArrayList<String>) {

        log("------------------" + arr.size)

        for (temp in arr) {

            val view = layoutInflater.inflate(R.layout.zoom_image_layout, null)
            val imageView = view.findViewById<ZoomImageView>(R.id.zoomImageView)

            ImageUtil.getInstance()
                .loadImageNoTransformation(this, imageView, R.drawable.load, temp)

            viewPagerList.add(view)
        }

        viewPager.currentItem = 0

        viewPager.adapter = object : PagerAdapter() {
            override fun isViewFromObject(view: View, `object`: Any): Boolean {
                return view == `object`

            }

            override fun getCount(): Int = viewPagerList.size

            override fun instantiateItem(container: ViewGroup, position: Int): Any {
                val v = viewPagerList[position]
                container.addView(v)
                return v
            }

            override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
                container.removeView(viewPagerList[position])
            }

        }

    }
}